﻿using PARK.Common.Const;
using PARK.Common.Entity;
using SqlSugar;
using System;
using Yitter.IdGenerator;

namespace PARK.CardAcct.Entitys
{
    /// <summary>
    /// 人员信息基类
    /// </summary>
    [SugarTable("base_employee")]
    [Tenant(ClaimConst.TENANT_ID)]
    public class EmployeeEntity
    {
        /// <summary>
        /// 自然主键
        /// </summary>
        [SugarColumn(ColumnName = "EmployeeId", IsPrimaryKey = true)]
        public string EmployeeId { get; set; }

        /// <summary>
        /// 工号
        /// </summary>
        [SugarColumn(ColumnName = "JobNum")]
        public string JobNum { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        [SugarColumn(ColumnName = "RealName")]
        public string RealName { get; set; }

        /// <summary>
        /// 性别
        /// </summary>
        [SugarColumn(ColumnName = "Gender")]
        public int? Gender { get; set; }
        /// <summary>
        /// 员工类型 1正式员工 2临时员工
        /// </summary>
        [SugarColumn(ColumnName = "EmployeType")]
        public int? EmployeType { get; set; }
        /// <summary>
        /// 部门Id
        /// </summary>
        [SugarColumn(ColumnName = "DepartId")]
        public string DepartId { get; set; }

        /// <summary>
        /// 部门名称
        /// </summary>
        [SugarColumn(ColumnName = "DepartName")]
        public string DepartName { get; set; }

        /// <summary>
        /// 头像
        /// </summary>
        [SugarColumn(ColumnName = "HeadIcon")]
        public string HeadIcon { get; set; }

        /// <summary>
        /// 手机
        /// </summary>
        [SugarColumn(ColumnName = "MobilePhone")]
        public string MobilePhone { get; set; }
        /// <summary>
        /// 手机_加密
        /// </summary>
        [SugarColumn(ColumnName = "MobilePhoneSf")]
        public string MobilePhoneSf { get; set; }        

        /// <summary>
        /// 描述
        /// </summary>
        [SugarColumn(ColumnName = "Description")]
        public string Description { get; set; }

        /// <summary>
        /// 是否已发卡 1是 0否
        /// </summary>
        [SugarColumn(ColumnName = "IsCard")]
        public int? IsCard { get; set; }

        /// <summary>
        /// 一卡通卡号
        /// </summary>
        [SugarColumn(ColumnName = "CardNo")]
        public string CardNo { get; set; }
        /// <summary>
        /// 长安通卡号
        /// </summary>
        [SugarColumn(ColumnName = "CatCardNo")]
        public string CatCardNo { get; set; }
        
        /// <summary>
        /// 有效期截止日
        /// </summary>
        [SugarColumn(ColumnName = "ExpiryEndDate")]
        public DateTime? ExpiryEndDate { get; set; }

        /// <summary>
        /// 福利余额
        /// </summary>
        [SugarColumn(ColumnName = "WelfareBalance")]
        public decimal WelfareBalance { get; set; }

        /// <summary>
        /// 充值余额
        /// </summary>
        [SugarColumn(ColumnName = "RechargeBalance")]
        public decimal RechargeBalance { get; set; }

        /// <summary>
        /// 最后更新时间
        /// </summary>
        [SugarColumn(ColumnName = "LastUpdateTime")]
        public DateTime? LastUpdateTime { get; set; }

        /// <summary>
        /// 卡户状态  1正常  2已冻结  3已挂失  0已禁用 4已销户 
        /// </summary>
        [SugarColumn(ColumnName = "AccStatus")]
        public int? AccStatus { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(ColumnName = "F_CreatorTime")]
        public DateTime? CreatorTime { get; set; }

        /// <summary>
        /// 创建用户
        /// </summary>
        [SugarColumn(ColumnName = "F_CreatorUserId")]
        public string CreatorUserId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "F_CreatorUserName")]
        public string CreatorUserName { get; set; }

        /// <summary>
        /// 修改时间
        /// </summary>
        [SugarColumn(ColumnName = "F_LastModifyTime")]
        public DateTime? LastModifyTime { get; set; }

        /// <summary>
        /// 修改用户
        /// </summary>
        [SugarColumn(ColumnName = "F_LastModifyUserId")]
        public string LastModifyUserId { get; set; }

        /// <summary>
        /// 修改用户
        /// </summary>
        [SugarColumn(ColumnName = "F_LastModifyUserName")]
        public string LastModifyUserName { get; set; }

        /// <summary>
        /// 删除标志
        /// </summary>
        [SugarColumn(ColumnName = "F_DeleteMark")]
        public int? DeleteMark { get; set; }

        /// <summary>
        /// 删除时间
        /// </summary>
        [SugarColumn(ColumnName = "F_DeleteTime")]
        public DateTime? DeleteTime { get; set; }

        /// <summary>
        /// 删除用户
        /// </summary>
        [SugarColumn(ColumnName = "F_DeleteUserId")]
        public string DeleteUserId { get; set; }

        /// <summary>
        /// 删除用户
        /// </summary>
        [SugarColumn(ColumnName = "F_DeleteUserName")]
        public string DeleteUserName { get; set; }

        /// <summary>
        /// 挂失日期
        /// </summary>
        [SugarColumn(ColumnName = "LossAccDate")]
        public DateTime? LossAccDate { get; set; }

        /// <summary>
        /// 销户日期
        /// </summary>
        [SugarColumn(ColumnName = "CancelAccDate")]
        public DateTime? CancelAccDate { get; set; }
        /// <summary>
        /// 微信绑定状态  0未绑定 1已成功绑定
        /// </summary>
        [SugarColumn(ColumnName = "Isauth")]
        public int? Isauth { get; set; }

        /// <summary>
        /// 所属公司Id
        /// </summary>
        [SugarColumn(ColumnName = "CompanyId")]
        public string CompanyId { get; set; }

        /// <summary>
        /// 公司名称
        /// </summary>
        [SugarColumn(ColumnName = "CompanyName")]
        public string CompanyName { get; set; }

        /// <summary>
        /// 卡片GUID
        /// </summary>
        [SugarColumn(ColumnName = "CardUID")]
        public string CardUID { get; set; }
        /// <summary>
        /// 卡片类型Id
        /// </summary>
        [SugarColumn(ColumnName = "CardTypeId")]
        public string CardTypeId { get; set; }
        /// <summary>
        /// 卡片类型名称
        /// </summary>
        [SugarColumn(ColumnName = "CardTypeName")]
        public string CardTypeName { get; set; }
        /// <summary>
        /// 卡片类型编号
        /// </summary>
        [SugarColumn(ColumnName = "CardTypeCode")]
        public string CardTypeCode { get; set; }
        /// <summary>
        /// 自增列
        /// </summary>
        [SugarColumn(ColumnName = "SortCode", IsIdentity = true)]
        public long SortCode { get; set; }

        /// <summary>
        /// 信息变更时间
        /// </summary>
        [SugarColumn(ColumnName = "EmpUpdate")]
        public DateTime EmpUpdate { get; set; }
        /// <summary>
        /// 是否需要删除离线名单
        /// </summary>
        [SugarColumn(ColumnName = "IsNeedDel")]
        public int IsNeedDel { get; set; }
        /// <summary>
        /// 生日
        /// </summary>
        [SugarColumn(ColumnName = "Birthday")]
        public string Birthday { get; set; }

        /// <summary>
        /// 超期状态  1已超期  0未超期 
        /// </summary>
        [SugarColumn(ColumnName = "OverdueStatus")]
        public int? OverdueStatus { get; set; }
        /// <summary>
        /// 职位
        /// </summary>
        [SugarColumn(ColumnName = "Eyejob")]
        public string Eyejob { get; set; }

        /// <summary>
        /// 就餐查询权限
        /// </summary>
        [SugarColumn(ColumnName = "AuthTsMenu")]
        public int AuthTsMenu { get; set; }

        /// <summary>
        /// 人脸采集 1已采集  2未采集
        /// </summary>
        [SugarColumn(ColumnName = "uni_is")]
        public int uni_is { get; set; }

        /// <summary>
        /// 宇泛平台用户Id
        /// </summary>
        [SugarColumn(ColumnName = "uni_admitGuid")]
        public string uni_admitGuid { get; set; }
        /// <summary>
        /// 宇泛平台用户_人像Id
        /// </summary>
        [SugarColumn(ColumnName = "uni_faceGuid")]
        public string uni_faceGuid { get; set; }
        /// <summary>
        /// 用户_人像url
        /// </summary>
        [SugarColumn(ColumnName = "uni_faceurl")]
        public string uni_faceurl { get; set; }

        /// <summary>
        /// 创建
        /// </summary>
        public virtual void Create()
        {
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.EmployeeId = YitIdHelper.NextId().ToString();
            this.CreatorTime = DateTime.Now;
            this.DeleteMark = 0;
            this.WelfareBalance = 0;
            this.RechargeBalance = 0;
            this.IsCard = string.IsNullOrEmpty(this.CardNo) ? 0 : 1;
            this.AccStatus = 1;
            this.Isauth = 0;
            this.IsNeedDel = 0;
            this.EmpUpdate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
            if (!string.IsNullOrEmpty(userId))
            {
                this.CreatorUserId = CreatorUserId == null ? userId : CreatorUserId;
                this.CreatorUserName = CreatorUserName == null ? userName : CreatorUserName;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        public virtual void LastModify(string Id)
        {
            this.EmployeeId = Id;
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.LastModifyTime = DateTime.Now;
            this.IsNeedDel = 0;
            this.EmpUpdate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
            if (!string.IsNullOrEmpty(userId))
            {
                this.LastModifyUserId = userId;
                this.LastModifyUserName = userName;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        public virtual void Delete()
        {
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.DeleteTime = DateTime.Now;
            this.DeleteMark = 1;
            this.IsNeedDel = 1;
            this.EmpUpdate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
            if (!string.IsNullOrEmpty(userId))
            {
                this.DeleteUserId = userId;
                this.DeleteUserName = userName;
            }
        }
    }
}
